package com.gohome.gohomechat.ui.fragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by dllo on 16/3/1.
 */
public class FragmentFactory {
    private static Map<Integer, Fragment> fragmentMap = new HashMap<>();
    private static FragmentFactory fragmentFactory;

    private FragmentFactory() {
    }

    public static FragmentFactory getInstance() {
        if (fragmentFactory == null)
            fragmentFactory = new FragmentFactory();
        return fragmentFactory;
    }

    public static Fragment createFragment(int position) {
        Fragment fragment = fragmentMap.get(position);
        if (fragment == null) {
            switch (position) {
                case 0:
                    fragment = new SessionFragment();
                    break;
                case 1:
                    fragment = new AddressFragment();
                    break;
                case 2:
                    fragment = new OtherFragment();
                    break;
                case 3:
                    fragment = new SetFragment();
                    break;
            }
            return fragment;
        }
        return fragment;
    }
}
